package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
//@Aspect
public class TimeAspect {
    //通过AOP 切面，统计业务层每个方法的执行耗时时长
    //@Around注解表示在目标方法执行前后织入代码
    //execution表达式表示拦截哪些方法
    //com.itheima.service.*.*(..)表示拦截com.itheima.service包下面的所有类的所有方法
    @Around("execution(* com.itheima.service.*.*(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        long end = System.currentTimeMillis();
        System.out.println(joinPoint.getSignature() + "方法执行时间：" + (end - start) + "毫秒");
        return result;
    }
}
